home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / screen / formrt.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  2.8 KB  |  101 lines

  1. ;void  format_right(strg,distance,color);
  2. ;  unsigned char  *strg,color;
  3. ;  unsigned short  distance;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _video_buffer:word
  7.     EXTRN  _video_page:byte
  8.     EXTRN  _snow_protect:byte
  9.  
  10. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  11.     ASSUME CS:_TEXT
  12.     PUBLIC _format_right
  13. _format_right proc near
  14.     cld            ;set direction flag
  15.     push bp            ;
  16.     mov  bp,sp        ;set stack frame
  17.     push di            ;
  18.     push si            ;
  19.     cmp  _memory_model,0    ;near or far?
  20.     jle  begin        ;jump if near
  21.     inc  bp            ;else add 2 to BP
  22.     inc  bp            ;
  23. begin:    mov  bh,_video_page    ;get BIOS page
  24.     mov  ax,_video_buffer    ;fetch _video_buffer
  25.     mov  es,ax        ;move to ES
  26.     push ds            ;save DS
  27.     mov  ah,3        ;BIOS call for curs pos
  28.     int  10h        ;DH-DL cursor row-col
  29.     mov  ax,160        ;bytes per row
  30.     mul  dh            ;times rows
  31.     sub  cx,cx        ;clear CX
  32.     mov  cl,dl        ;cols to CX
  33.     shl  cl,1        ;double for attributes
  34.     add  ax,cx        ;add to row offset
  35.     mov  di,ax        ;place offset in DI
  36.     mov  bl,_snow_protect    ;fetch _snow_protect
  37.     cmp  _memory_model,2    ;data near or far?
  38.     jb   L0            ;jump if near
  39.     lds  si,dword ptr[bp+4] ;DS:SI pts to Strg
  40.     inc  bp            ;add 2 to BP since dword ptr    
  41.     inc  bp            ;
  42.     jmp  short L00        ;
  43. L0:    mov  si,[bp+4]        ;near case
  44. L00:    mov  byte ptr[bp+4],bl  ;keep _snow_protect
  45.     cmp  byte ptr[si],0    ;test for null string
  46.     je   L5            ;
  47.     push dx            ;save cursor values
  48.     push bx            ;save video page
  49.     mov  bh,[bp+8]        ;attribute to BH
  50.     sub  cx,cx        ;count string length in CX
  51. L000:    inc  si            ;move SI to end of string
  52.     inc  cx            ;inc string length counter
  53.     cmp  byte ptr[si],0    ;test for end of string
  54.     jne  L000        ;loop
  55.     dec  si            ;pull back pointer
  56. L1:    mov  bl,[si]        ;get a char
  57.     cmp  byte ptr[bp+4],0    ;protect against snow?
  58.     je   L4            ;jump if not
  59.     mov  dx,3dah        ;status byte address
  60. L2:    in   al,dx        ;get status byte
  61.     test al,1        ;test bit
  62.     jnz  L2            ;loop till 0
  63.     cli            ;disable interrupts
  64. L3:    in   al,dx        ;get status byte
  65.     test al,1        ;test bit
  66.     jz   L3            ;loop till 1
  67. L4:    mov  ax,bx        ;get char-attribute
  68.     stosw            ;write it
  69.     sub  di,4        ;pull back scrn ptr
  70.     dec  si            ;dec Strg ptr
  71.     loop L1            ;go do next char
  72.     sti            ;reenable interrupts
  73.     pop  bx            ;video page back to BH
  74.     pop  dx            ;restore cursor values
  75. L5:    mov  cx,[bp+6]        ;get new cursor offset
  76.     test cx,8000h        ;negative?
  77.     jz   L6            ;jump if not
  78.     neg  CX            ;make positive
  79.     add  dh,cl        ;add to row offset
  80.     cmp  dh,24        ;bottom of screen?
  81.     jb   L7            ;jump if not
  82.     mov  dh,24        ;else edge of screen
  83.     jmp  short L7        ;to set cursor
  84. L6:    add  dl,cl        ;add to col offset
  85.     cmp  dl,79        ;off screen?
  86.     jb   L7            ;jump if not
  87.     mov  dl,79        ;else edge of screen
  88. L7:    mov  ah,2        ;BIOS func to set curs
  89.     int  10h        ;set new cursor pos
  90.     pop  ds            ;
  91.     pop  si            ;
  92.     pop  di            ;
  93.     pop  bp            ;
  94.     cmp  _memory_model,0    ;quit
  95.     jle  quit        ;
  96.     db   0CBh        ;RET far
  97. quit:    ret            ;RET near
  98. _format_right endp
  99. _TEXT    ENDS
  100.     END
  101.